/**
 * Created by Maxjzm on 2017/4/17.
 */
public class test {
    /*
	 * 快速排序
	 */
    public static void sort(int[] array, int start, int end){
        if(start>=end) return;
        int i=start;
        int j=end;
        int index=array[i];
        while(i<j){
            while(i<j&&index<=array[j]){
                j--;
            }
            if(i<j){
                array[i]=array[j];
                i++;
            }
            while(i<j&&index>array[i]){
                i++;
            }
            if(i<j){
                array[j]=array[i];
                j--;
            }
        }
        array[i]=index;
        sort(array,start,i-1);
        sort(array,i+1,end);


    }
    public static void quickSort(int[] array){
        sort(array,0,array.length-1);
    }
    public static void main(String[] args) {

        int[] a = { 22, 13, 24, 5, 88, 78, 8, 10, 35 ,1,2};
        quickSort(a);
        System.out.print("堆排序的结果是：");
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println("\n"
                + "===================================================");

    }

}
